package com.tanhua.server.task;

import com.tanhua.commons.SoulConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Component
@Slf4j
//redis定时任务类
public class RedisTask {
    @Autowired
    private StringRedisTemplate redisTemplate;

    //在每天0时0分0秒时执行操作
    @Scheduled(cron = "0 0 0 * * ?")
    public void cleanGetSoundTimes (){
        //获取前缀为GET_SOUND_TIMES_的所有key
        String getSoundTimes = "GET_SOUND_TIMES_*";
        String sendSoundTimes = SoulConstants.SEND_SOUND_TIME + "*";
        String getSoundUserId = "ALREADY_GET_USERID_*";

        List<String> keys = Arrays.asList(getSoundTimes, sendSoundTimes, getSoundUserId);

        redisTemplate.delete(keys);
    }
}

